package simplecoder.domain;

import simplecoder.domain.jsp.Edit;
import simplecoder.domain.jsp.Grid;
import simplecoder.domain.jsp.Main;
import simplecoder.domain.jsp.Page;

public class Module {

	private String title;//模块名称，比如“用户”
	private String sourcePath;//很多项目都不是以src作为第一个目录的
	private Pojo pojo;
	private Clazz action;
	private Clazz service;
	private Clazz dao;
	
	private Page main;
	private Page grid;
	private Page edit;
	
	private static Module module;
	
	public static Module getInstance(){
		if(module==null){
			throw new RuntimeException("Module 未被初始化 ");
		}
		return module;
	}
	
	private Module(){
		
	}
	
	public static Module create(String sourcePath, String className, String packName){
		System.out.println("创建module");
		if(module==null){
			module = new Module();
		}
		Pojo pojo = new Pojo(className, packName);
		module.setPojo(pojo);
		module.initClasss();
		module.sourcePath = sourcePath;
		return module;
	}
	
	private void initClasss(){
		//java
		action = new Action();
		service = new Service();
		dao = new Dao();
		
		//这里一定要倒过来
		dao.init(module);
		service.init(module);
		action.init(module);
		
		
		
		//java
		main = new Main();
		grid = new Grid();
		edit = new Edit();
		main.init(module);
		grid.init(module);
		edit.init(module);
		
	}
	
	public void setTitle(String title) {
		this.title = title;
	}
	
	public String getTitle() {
		return title;
	}
	
	public String getSourcePath() {
		return sourcePath;
	}
	
	public Pojo getPojo(){
		return pojo;
	}
	
	public void setPojo(Pojo pojo) {
		this.pojo = pojo;
	}
	
	public Clazz getAction() {
		return action;
	}
	
	public Clazz getService() {
		return service;
	}
	
	public Clazz getDao() {
		return dao;
	}
	
	public Page getEdit() {
		return edit;
	}
	
	public Page getMain() {
		return main;
	}
	
	public Page getGrid() {
		return grid;
	}
	
	
}
